package sharemem

import (
	"server_cluster/chat/chat_config"
)
// Index 全局索引对象
type Index struct {
	ShmUser_map map[int64]*ShmUser									// 玩家map key:uid value:Usr指针
}

// 进程内全局变量
var index_game Index

func GetShmUserByUid(uid int64) *ShmUser {
	v,ok := GetShmUserMap()[uid]
	if !ok {
		return nil
	}
	return v
}
// 活跃用户map
func GetShmUserMap() map[int64]*ShmUser {
	if index_game.ShmUser_map == nil {
		index_game.ShmUser_map = make(map[int64]*ShmUser, chat_config.SHM_USER_MAX)
	}
	return index_game.ShmUser_map
}
func SetShmUserMap(id int64, user *ShmUser) {
	user_map := GetShmUserMap()
	user_map[id] = user
}
func DeleteShmUserMap(id int64) {
	delete(GetShmUserMap(), id)
}
// 用户操作map

func (u *ShmUser) DeleteShmUserAllMap() {
	//u.DeleteActionMap()
}

// 初始化user map
func Init_all_user_index() {
	var i int32
	for i = 0; i < chat_config.SHM_USER_MAX; i++ {
		if Myshm.ShmUser[i].IsUse() {
			SetShmUserMap(Myshm.ShmUser[i].GetId(), &(Myshm.ShmUser[i]))
			//Myshm.ShmUser[i].InitShmUserAllMap()
		}
	}
}
